# coding=utf-8
import urllib
import re
def editor(string):
    string = string.replace('',' ')
    string = string.replace('<\P>','\n')
    labels = re.compile('<.*?>')
    labels.sub(' ',string)
    return string

def make(part):
    title = re.search('<title>.*</title>', part).group()[7:-8]
    link = re.search('<link>.*?</link>', part).group()[6:-8]
    art = re.search('<description>.*?</P><div style=\"border-top', part,re.S).group()[13:-26]
    art = editor(art)
    return {'tit' : title, 'link' : link, 'art' : art}


xml = urllib.urlopen('http://blog.sina.com.cn/rss/twocold.xml').read()
pattern = re.compile(r'<title>.*?</title>\s*<link>.*?</link>\s*<description>.*?</P><div style=\"border-top', re.S)
finds = pattern.findall(xml)
for i in finds:
    print make(i)['art']


